package com.example.day01

import android.os.Bundle
import android.widget.SimpleAdapter
import android.widget.Spinner
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class cityActivity : AppCompatActivity() {
    // 0. 数据类
    data class CityData(val icon: Int, val text: String, val intor: String)

    private val cityList: List<CityData> = listOf<CityData>(
        CityData(R.drawable.bj, "北京", "北京烤鸭"),
        CityData(R.drawable.sh, "上海", "123"),
        CityData(R.drawable.gz, "广州", "123"),
        CityData(R.drawable.sz, "深圳", "123"),
        CityData(R.drawable.hz, "杭州", "123"),
        CityData(R.drawable.nj, "南京", "123"),
    )
    private var spCity: Spinner? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_city)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        spCity = findViewById(R.id.spinner_icon)
        spCity?.adapter = SimpleAdapter(
            this,
            cityList.map {
                mapOf("icon" to it.icon, "text" to it.text, "intor" to it.intor)
            },
            R.layout.item_icon,
            arrayOf("icon", "text", "intor"),
            intArrayOf(R.id.icon, R.id.text, R.id.text1)
        )


    }
}